%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Yi-Chao Chen
%% 2013.12.31 @ UT Austin
%%
%% - Input:
%%
%%
%% - Output:
%%
%%
%% e.g.
%%
%%     
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function plot_anom()
    addpath('../utils');

    %% --------------------
    %% DEBUG
    %% --------------------
    DEBUG0 = 0;
    DEBUG1 = 1;
    DEBUG2 = 1;

    PLOT_PURE_RAND1 = 1;
    PLOT_PR_THRESH1 = 0;
    PLOT_PR_THRESH2 = 0;
    PLOT_PR_THRESH3 = 0;
    PLOT_PR_THRESH4 = 0;

    PLOT_PURE_RAND2 = 1;

    PLOT_TIME_RAND1 = 1;
    PLOT_TR_THRESH1 = 0;
    PLOT_TR_THRESH2 = 0;

    PLOT_ELEM_RAND1 = 1;
    PLOT_ER_THRESH1 = 0;
    PLOT_ER_THRESH2 = 0;
    
    PLOT_ELEM_SYNC1 = 1;
    PLOT_ES_THRESH1 = 0;
    PLOT_ES_THRESH2 = 0;

    PLOT_ROW_RAND1  = 1;
    PLOT_RR_THRESH1 = 0;
    PLOT_RR_THRESH2 = 0;

    PLOT_COL_RAND1  = 1;
    PLOT_CR_THRESH1 = 0;
    PLOT_CR_THRESH2 = 0;


    markers = {'+','o','*','.','x','s','d','^','>','<','p','h'};
    lines   = {'-','--',':','-.'};
    font_size = 18;
                        


    %% --------------------
    %% Variable
    %% --------------------
    srmf_dir    = '../condor_data/subtask_compressive_sensing/condor/output/';
    output_dir  = '../processed_data/subtask_plot_pred/figures_anom/';

    scheme = 'srmf_based_pred';
    seeds  = [1];
    files = {'tm_totem.'};

    % sigma_mags = [0.05 0.2 0.4 0.6 1];
    % sigma_noises = [0 0.001 0.01 0.1];
    % threshs = [0.2 0.3 0.4 0.5 0.6 0.7 0.8];
    sigma_mags = [0.4];
    sigma_noises = [0.01];
    threshs = [0.6];

    nm = 12;


    %% --------------------
    %% Check input
    %% --------------------
    

    %% --------------------
    %% Main starts
    %% --------------------
    for file = files
        file = char(file);
        

        %% --------------------
        %% in PureRandLoss, see how thresh change impact results
        %% --------------------
        threshs = [0.2 0.3 0.4 0.5 0.6 0.7 0.8];
        %% PureRandLoss
        drop_ele_mode = 'elem';
        drop_mode     = 'ind';
        elem_frac     = 1;
        loss_rates    = [0.1 0.2 0.4 0.6 0.8];
        burst_size    = 1;
        %% file, group_size, r, opt_swap_mat, opt_type, opt_dim, drop_ele_mode, drop_mode, elem_frac, loss_rates, burst_size, sigma_mag, sigma_noise, thresh

        if PLOT_PR_THRESH1
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;
            %%    - loss_rate = 0.1
            loss_rate         = 0.1;
            metrics_srmf      = zeros(nm, length(threshs));
            metrics_srmf_knn  = zeros(nm, length(threshs));
            metrics_lens      = zeros(nm, length(threshs));
            metrics_lens_knn  = zeros(nm, length(threshs));
            metrics_lens_knn2 = zeros(nm, length(threshs));
            for i = [1:length(threshs)]
                thresh = threshs(i);
                metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
            end

            %% plot f1
            ix = 11;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_pr.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.f1'], ...
                'threshold', 'F1');

            %% plot prec
            ix = 9;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_pr.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.prec'], ...
                'threshold', 'precision');

            %% plot recall
            ix = 10;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_pr.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.recall'], ...
                'threshold', 'recall');

            %% plot jaccard
            ix = 12;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_pr.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.jaccard'], ...
                'threshold', 'jaccard');

        end %% end plot threshold 1


        if PLOT_PR_THRESH2
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;
            %%    - loss_rate = 0.2
            loss_rate         = 0.2;
            metrics_srmf      = zeros(nm, length(threshs));
            metrics_srmf_knn  = zeros(nm, length(threshs));
            metrics_lens      = zeros(nm, length(threshs));
            metrics_lens_knn  = zeros(nm, length(threshs));
            metrics_lens_knn2 = zeros(nm, length(threshs));
            for i = [1:length(threshs)]
                thresh = threshs(i);
                metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
            end

            %% plot f1
            ix = 11;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_pr.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.f1'], ...
                'threshold', 'F1');

            %% plot prec
            ix = 9;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_pr.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.prec'], ...
                'threshold', 'precision');

            %% plot recall
            ix = 10;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_pr.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.recall'], ...
                'threshold', 'recall');

            %% plot jaccard
            ix = 12;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_pr.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.jaccard'], ...
                'threshold', 'jaccard');

        end % end plot threshold 2


        if PLOT_PR_THRESH3
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;
            %%    - loss_rate = 0.2
            loss_rate         = 0.6;
            metrics_srmf      = zeros(nm, length(threshs));
            metrics_srmf_knn  = zeros(nm, length(threshs));
            metrics_lens      = zeros(nm, length(threshs));
            metrics_lens_knn  = zeros(nm, length(threshs));
            metrics_lens_knn2 = zeros(nm, length(threshs));
            for i = [1:length(threshs)]
                thresh = threshs(i);
                metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
            end

            %% plot f1
            ix = 11;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_pr.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.f1'], ...
                'threshold', 'F1');

            %% plot prec
            ix = 9;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_pr.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.prec'], ...
                'threshold', 'precision');

            %% plot recall
            ix = 10;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_pr.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.recall'], ...
                'threshold', 'recall');

            %% plot jaccard
            ix = 12;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_pr.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.jaccard'], ...
                'threshold', 'jaccard');

        end % end plot threshold 3


        if PLOT_PR_THRESH4
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;
            %%    - loss_rate = 0.2
            loss_rate         = 0.8;
            metrics_srmf      = zeros(nm, length(threshs));
            metrics_srmf_knn  = zeros(nm, length(threshs));
            metrics_lens      = zeros(nm, length(threshs));
            metrics_lens_knn  = zeros(nm, length(threshs));
            metrics_lens_knn2 = zeros(nm, length(threshs));
            for i = [1:length(threshs)]
                thresh = threshs(i);
                metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
            end

            %% plot f1
            ix = 11;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_pr.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.f1'], ...
                'threshold', 'F1');

            %% plot prec
            ix = 9;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_pr.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.prec'], ...
                'threshold', 'precision');

            %% plot recall
            ix = 10;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_pr.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.recall'], ...
                'threshold', 'recall');

            %% plot jaccard
            ix = 12;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_pr.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.jaccard'], ...
                'threshold', 'jaccard');

        end % end plot threshold 4


        if PLOT_PURE_RAND1
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;

            thresh = 0.6;
            
            metrics_srmf      = zeros(nm, length(loss_rates));
            metrics_srmf_knn  = zeros(nm, length(loss_rates));
            metrics_lens      = zeros(nm, length(loss_rates));
            metrics_lens_knn  = zeros(nm, length(loss_rates));
            metrics_lens_knn2 = zeros(nm, length(loss_rates));
            for i = [1:length(loss_rates)]
                loss_rate = loss_rates(i);
                metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
            end

            %% plot mse
            ix = 1;
            plot_my(loss_rates, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.PureRandLoss.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.mse'], ...
                'loss rate', 'MSE');

            %% plot mae
            ix = 2;
            plot_my(loss_rates, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.PureRandLoss.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.mae'], ...
                'loss rate', 'MAE');

            %% plot cc
            ix = 3;
            plot_my(loss_rates, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.PureRandLoss.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.cc'], ...
                'loss rate', 'correlation coefficient');
        end % end PLOT_PURE_RAND1


        if PLOT_PURE_RAND2
            %% 1. mag = 0.4, noise = 0.01
            sigma_mag   = 1;
            sigma_noise = 0.1;

            metrics_srmf      = zeros(nm, length(loss_rates));
            metrics_srmf_knn  = zeros(nm, length(loss_rates));
            metrics_lens      = zeros(nm, length(loss_rates));
            metrics_lens_knn  = zeros(nm, length(loss_rates));
            metrics_lens_knn2 = zeros(nm, length(loss_rates));
            for i = [1:length(loss_rates)]
                loss_rate = loss_rates(i);
                metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, 0.6);
                metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, 0.6);
                metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, 0.6);
                metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, 0.6);
                metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, 0.6);
            end

            %% plot f1
            ix = 11;
            plot_my(loss_rates, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.PureRandLoss.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.f1'], ...
                'loss rate', 'MSE');

            %% plot jaccard
            ix = 12;
            plot_my(loss_rates, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.PureRandLoss.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.jaccard'], ...
                'loss rate', 'MAE');

            %% plot prec
            ix = 9;
            plot_my(loss_rates, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.PureRandLoss.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.prec'], ...
                'loss rate', 'correlation coefficient');

            %% plot recall
            ix = 10;
            plot_my(loss_rates, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.PureRandLoss.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.recall'], ...
                'loss rate', 'correlation coefficient');
        end % end PLOT_PURE_RAND2





        %% --------------------
        %% TimeRandLoss
        %% --------------------
        %% TimeRandLoss
        drop_ele_mode = 'elem';
        drop_mode     = 'ind';
        elem_fracs    = [0.1 0.2 0.4 0.6 1];
        loss_rates    = [0.1 0.2 0.4 0.6 0.8];
        burst_size    = 1;

        if PLOT_TIME_RAND1
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;

            for loss_rate = loss_rates
                thresh = 0.6;
                
                metrics_srmf      = zeros(nm, length(elem_fracs));
                metrics_srmf_knn  = zeros(nm, length(elem_fracs));
                metrics_lens      = zeros(nm, length(elem_fracs));
                metrics_lens_knn  = zeros(nm, length(elem_fracs));
                metrics_lens_knn2 = zeros(nm, length(elem_fracs));
                for i = [1:length(elem_fracs)]
                    elem_frac = elem_fracs(i);
                    metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                end

                %% plot mse
                ix = 1;
                plot_my(elem_fracs, ...
                    [metrics_srmf(ix, :); ...
                     metrics_srmf_knn(ix, :); ...
                     metrics_lens(ix, :); ...
                     metrics_lens_knn(ix, :); ...
                     metrics_lens_knn2(ix, :);], ...
                    {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                    [output_dir file '.TimeRandLoss' int2str(loss_rate*100) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.mse'], ...
                    'loss rate', 'MSE');

                %% plot mae
                ix = 2;
                plot_my(elem_fracs, ...
                    [metrics_srmf(ix, :); ...
                     metrics_srmf_knn(ix, :); ...
                     metrics_lens(ix, :); ...
                     metrics_lens_knn(ix, :); ...
                     metrics_lens_knn2(ix, :);], ...
                    {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                    [output_dir file '.TimeRandLoss' int2str(loss_rate*100) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.mae'], ...
                    'loss rate', 'MAE');

                %% plot cc
                ix = 3;
                plot_my(elem_fracs, ...
                    [metrics_srmf(ix, :); ...
                     metrics_srmf_knn(ix, :); ...
                     metrics_lens(ix, :); ...
                     metrics_lens_knn(ix, :); ...
                     metrics_lens_knn2(ix, :);], ...
                    {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                    [output_dir file '.TimeRandLoss' int2str(loss_rate*100) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.cc'], ...
                    'loss rate', 'correlation coefficient');
            end
        end % end PLOT TIME RAND

        if PLOT_TR_THRESH1
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;
            
            %% - elem_frac = 0.2
            loss_rate = 0.6;
            elem_frac = 0.2;

            metrics_srmf      = zeros(nm, length(threshs));
            metrics_srmf_knn  = zeros(nm, length(threshs));
            metrics_lens      = zeros(nm, length(threshs));
            metrics_lens_knn  = zeros(nm, length(threshs));
            metrics_lens_knn2 = zeros(nm, length(threshs));
            for i = [1:length(threshs)]
                thresh = threshs(i);
                metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
            end

            %% plot f1
            ix = 11;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_tr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.f1'], ...
                'threshold', 'F1');

            %% plot prec
            ix = 9;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_tr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.prec'], ...
                'threshold', 'precision');

            %% plot recall
            ix = 10;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_tr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.recall'], ...
                'threshold', 'recall');

            %% plot jaccard
            ix = 12;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_tr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.jaccard'], ...
                'threshold', 'jaccard');
        end % end plot threshold 1 for time rand

        if PLOT_TR_THRESH2
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;
            
            %% - elem_frac = 0.6
            loss_rate = 0.6;
            elem_frac = 0.6;

            metrics_srmf      = zeros(nm, length(threshs));
            metrics_srmf_knn  = zeros(nm, length(threshs));
            metrics_lens      = zeros(nm, length(threshs));
            metrics_lens_knn  = zeros(nm, length(threshs));
            metrics_lens_knn2 = zeros(nm, length(threshs));
            for i = [1:length(threshs)]
                thresh = threshs(i);
                metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
            end

            %% plot f1
            ix = 11;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_tr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.f1'], ...
                'threshold', 'F1');

            %% plot prec
            ix = 9;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_tr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.prec'], ...
                'threshold', 'precision');

            %% plot recall
            ix = 10;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_tr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.recall'], ...
                'threshold', 'recall');

            %% plot jaccard
            ix = 12;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_tr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.jaccard'], ...
                'threshold', 'jaccard');
        end % end plot threshold 2 for time rand




        %% --------------------
        %% ElemRandLoss
        %% --------------------
        %% ElemRandLoss
        drop_ele_mode = 'elem';
        drop_mode     = 'ind';
        elem_fracs    = [0.1 0.2 0.4 0.6];
        loss_rates    = [0.1 0.2 0.4 0.6 0.8];
        burst_size    = 1;

        if PLOT_ELEM_RAND1
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;

            thresh = 0.6;
            
            for elem_frac = elem_fracs
                metrics_srmf      = zeros(nm, length(loss_rates));
                metrics_srmf_knn  = zeros(nm, length(loss_rates));
                metrics_lens      = zeros(nm, length(loss_rates));
                metrics_lens_knn  = zeros(nm, length(loss_rates));
                metrics_lens_knn2 = zeros(nm, length(loss_rates));
                for i = [1:length(loss_rates)]
                    loss_rate = loss_rates(i);
                    metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                end

                %% plot mse
                ix = 1;
                plot_my(loss_rates, ...
                    [metrics_srmf(ix, :); ...
                     metrics_srmf_knn(ix, :); ...
                     metrics_lens(ix, :); ...
                     metrics_lens_knn(ix, :); ...
                     metrics_lens_knn2(ix, :);], ...
                    {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                    [output_dir file '.ElemRandLoss' int2str(elem_frac*100) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.mse'], ...
                    'loss rate', 'MSE');

                %% plot mae
                ix = 2;
                plot_my(loss_rates, ...
                    [metrics_srmf(ix, :); ...
                     metrics_srmf_knn(ix, :); ...
                     metrics_lens(ix, :); ...
                     metrics_lens_knn(ix, :); ...
                     metrics_lens_knn2(ix, :);], ...
                    {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                    [output_dir file '.ElemRandLoss' int2str(elem_frac*100) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.mae'], ...
                    'loss rate', 'MAE');

                %% plot cc
                ix = 3;
                plot_my(loss_rates, ...
                    [metrics_srmf(ix, :); ...
                     metrics_srmf_knn(ix, :); ...
                     metrics_lens(ix, :); ...
                     metrics_lens_knn(ix, :); ...
                     metrics_lens_knn2(ix, :);], ...
                    {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                    [output_dir file '.ElemRandLoss' int2str(elem_frac*100) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.cc'], ...
                    'loss rate', 'correlation coefficient');
            end
        end % end PLOT_ELEM_RAND1

        if PLOT_ER_THRESH1
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;
            
            %% - loss_rate = 0.2
            loss_rate = 0.2;
            elem_frac = 0.6;

            metrics_srmf      = zeros(nm, length(threshs));
            metrics_srmf_knn  = zeros(nm, length(threshs));
            metrics_lens      = zeros(nm, length(threshs));
            metrics_lens_knn  = zeros(nm, length(threshs));
            metrics_lens_knn2 = zeros(nm, length(threshs));
            for i = [1:length(threshs)]
                thresh = threshs(i);
                metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
            end

            %% plot f1
            ix = 11;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_er' num2str(elem_frac*100) '.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.f1'], ...
                'threshold', 'F1');

            %% plot prec
            ix = 9;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_er' num2str(elem_frac*100) '.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.prec'], ...
                'threshold', 'precision');

            %% plot recall
            ix = 10;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_er' num2str(elem_frac*100) '.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.recall'], ...
                'threshold', 'recall');

            %% plot jaccard
            ix = 12;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_er' num2str(elem_frac*100) '.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.jaccard'], ...
                'threshold', 'jaccard');
        end % end plot threshold 1 for elem rand

        if PLOT_ER_THRESH2
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;
            
            %% - loss_rate = 0.6
            loss_rate = 0.6;
            elem_frac = 0.6;

            metrics_srmf      = zeros(nm, length(threshs));
            metrics_srmf_knn  = zeros(nm, length(threshs));
            metrics_lens      = zeros(nm, length(threshs));
            metrics_lens_knn  = zeros(nm, length(threshs));
            metrics_lens_knn2 = zeros(nm, length(threshs));
            for i = [1:length(threshs)]
                thresh = threshs(i);
                metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
            end

            %% plot f1
            ix = 11;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_er' num2str(elem_frac*100) '.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.f1'], ...
                'threshold', 'F1');

            %% plot prec
            ix = 9;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_er' num2str(elem_frac*100) '.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.prec'], ...
                'threshold', 'precision');

            %% plot recall
            ix = 10;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_er' num2str(elem_frac*100) '.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.recall'], ...
                'threshold', 'recall');

            %% plot jaccard
            ix = 12;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_er' num2str(elem_frac*100) '.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.jaccard'], ...
                'threshold', 'jaccard');
        end % end plot threshold 2 for elem rand



        %% --------------------
        %% ElemSyncLoss
        %% --------------------
        %% ElemSyncLoss
        drop_ele_mode = 'elem';
        drop_mode     = 'syn';
        elem_fracs    = [0.3];
        loss_rates    = [0.1 0.2 0.4 0.6 0.8];
        burst_size    = 1;

        if PLOT_ELEM_SYNC1
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;

            thresh = 0.6;
            
            for elem_frac = elem_fracs
                metrics_srmf      = zeros(nm, length(loss_rates));
                metrics_srmf_knn  = zeros(nm, length(loss_rates));
                metrics_lens      = zeros(nm, length(loss_rates));
                metrics_lens_knn  = zeros(nm, length(loss_rates));
                metrics_lens_knn2 = zeros(nm, length(loss_rates));
                for i = [1:length(loss_rates)]
                    loss_rate = loss_rates(i);
                    metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                end

                %% plot mse
                ix = 1;
                plot_my(loss_rates, ...
                    [metrics_srmf(ix, :); ...
                     metrics_srmf_knn(ix, :); ...
                     metrics_lens(ix, :); ...
                     metrics_lens_knn(ix, :); ...
                     metrics_lens_knn2(ix, :);], ...
                    {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                    [output_dir file '.ElemSyncLoss' int2str(elem_frac*100) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.mse'], ...
                    'loss rate', 'MSE');

                %% plot mae
                ix = 2;
                plot_my(loss_rates, ...
                    [metrics_srmf(ix, :); ...
                     metrics_srmf_knn(ix, :); ...
                     metrics_lens(ix, :); ...
                     metrics_lens_knn(ix, :); ...
                     metrics_lens_knn2(ix, :);], ...
                    {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                    [output_dir file '.ElemSyncLoss' int2str(elem_frac*100) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.mae'], ...
                    'loss rate', 'MAE');

                %% plot cc
                ix = 3;
                plot_my(loss_rates, ...
                    [metrics_srmf(ix, :); ...
                     metrics_srmf_knn(ix, :); ...
                     metrics_lens(ix, :); ...
                     metrics_lens_knn(ix, :); ...
                     metrics_lens_knn2(ix, :);], ...
                    {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                    [output_dir file '.ElemSyncLoss' int2str(elem_frac*100) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.cc'], ...
                    'loss rate', 'correlation coefficient');
            end
        end % end PLOT_ELEM_RAND1

        if PLOT_ES_THRESH1
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;
            
            %% - loss_rate = 0.2
            loss_rate = 0.2;
            elem_frac = 0.3;

            metrics_srmf      = zeros(nm, length(threshs));
            metrics_srmf_knn  = zeros(nm, length(threshs));
            metrics_lens      = zeros(nm, length(threshs));
            metrics_lens_knn  = zeros(nm, length(threshs));
            metrics_lens_knn2 = zeros(nm, length(threshs));
            for i = [1:length(threshs)]
                thresh = threshs(i);
                metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
            end

            %% plot f1
            ix = 11;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_es' num2str(elem_frac*100) '.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.f1'], ...
                'threshold', 'F1');

            %% plot prec
            ix = 9;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_es' num2str(elem_frac*100) '.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.prec'], ...
                'threshold', 'precision');

            %% plot recall
            ix = 10;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_es' num2str(elem_frac*100) '.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.recall'], ...
                'threshold', 'recall');

            %% plot jaccard
            ix = 12;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_es' num2str(elem_frac*100) '.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.jaccard'], ...
                'threshold', 'jaccard');
        end % end plot threshold 1 for elem rand

        if PLOT_ES_THRESH2
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;
            
            %% - loss_rate = 0.6
            loss_rate = 0.6;
            elem_frac = 0.3;

            metrics_srmf      = zeros(nm, length(threshs));
            metrics_srmf_knn  = zeros(nm, length(threshs));
            metrics_lens      = zeros(nm, length(threshs));
            metrics_lens_knn  = zeros(nm, length(threshs));
            metrics_lens_knn2 = zeros(nm, length(threshs));
            for i = [1:length(threshs)]
                thresh = threshs(i);
                metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
            end

            %% plot f1
            ix = 11;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_es' num2str(elem_frac*100) '.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.f1'], ...
                'threshold', 'F1');

            %% plot prec
            ix = 9;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_es' num2str(elem_frac*100) '.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.prec'], ...
                'threshold', 'precision');

            %% plot recall
            ix = 10;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_es' num2str(elem_frac*100) '.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.recall'], ...
                'threshold', 'recall');

            %% plot jaccard
            ix = 12;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_es' num2str(elem_frac*100) '.loss' num2str(loss_rate) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.jaccard'], ...
                'threshold', 'jaccard');
        end % end plot threshold 2 for elem rand


        %% --------------------
        %% RowRandLoss
        %% --------------------
        %% RowRandLoss
        drop_ele_mode = 'row';
        drop_mode     = 'ind';
        elem_fracs    = [0.1 0.2 0.4 0.6 0.8];
        loss_rates    = [0.5];
        burst_size    = 1;

        if PLOT_ROW_RAND1
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;

            for loss_rate = loss_rates
                thresh = 0.6;
                
                metrics_srmf      = zeros(nm, length(elem_fracs));
                metrics_srmf_knn  = zeros(nm, length(elem_fracs));
                metrics_lens      = zeros(nm, length(elem_fracs));
                metrics_lens_knn  = zeros(nm, length(elem_fracs));
                metrics_lens_knn2 = zeros(nm, length(elem_fracs));
                for i = [1:length(elem_fracs)]
                    elem_frac = elem_fracs(i);
                    metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                end

                %% plot mse
                ix = 1;
                plot_my(elem_fracs, ...
                    [metrics_srmf(ix, :); ...
                     metrics_srmf_knn(ix, :); ...
                     metrics_lens(ix, :); ...
                     metrics_lens_knn(ix, :); ...
                     metrics_lens_knn2(ix, :);], ...
                    {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                    [output_dir file '.RowRandLoss' int2str(loss_rate*100) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.mse'], ...
                    'loss rate', 'MSE');

                %% plot mae
                ix = 2;
                plot_my(elem_fracs, ...
                    [metrics_srmf(ix, :); ...
                     metrics_srmf_knn(ix, :); ...
                     metrics_lens(ix, :); ...
                     metrics_lens_knn(ix, :); ...
                     metrics_lens_knn2(ix, :);], ...
                    {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                    [output_dir file '.RowRandLoss' int2str(loss_rate*100) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.mae'], ...
                    'loss rate', 'MAE');

                %% plot cc
                ix = 3;
                plot_my(elem_fracs, ...
                    [metrics_srmf(ix, :); ...
                     metrics_srmf_knn(ix, :); ...
                     metrics_lens(ix, :); ...
                     metrics_lens_knn(ix, :); ...
                     metrics_lens_knn2(ix, :);], ...
                    {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                    [output_dir file '.RowRandLoss' int2str(loss_rate*100) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.cc'], ...
                    'loss rate', 'correlation coefficient');
            end
        end % end PLOT ROW RAND

        if PLOT_RR_THRESH1
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;
            
            %% - elem_frac = 0.2
            loss_rate = 0.5;
            elem_frac = 0.2;

            metrics_srmf      = zeros(nm, length(threshs));
            metrics_srmf_knn  = zeros(nm, length(threshs));
            metrics_lens      = zeros(nm, length(threshs));
            metrics_lens_knn  = zeros(nm, length(threshs));
            metrics_lens_knn2 = zeros(nm, length(threshs));
            for i = [1:length(threshs)]
                thresh = threshs(i);
                metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
            end

            %% plot f1
            ix = 11;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_rr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.f1'], ...
                'threshold', 'F1');

            %% plot prec
            ix = 9;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_rr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.prec'], ...
                'threshold', 'precision');

            %% plot recall
            ix = 10;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_rr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.recall'], ...
                'threshold', 'recall');

            %% plot jaccard
            ix = 12;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_rr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.jaccard'], ...
                'threshold', 'jaccard');
        end % end plot threshold 1 for row rand

        if PLOT_RR_THRESH2
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;
            
            %% - elem_frac = 0.6
            loss_rate = 0.5;
            elem_frac = 0.6;

            metrics_srmf      = zeros(nm, length(threshs));
            metrics_srmf_knn  = zeros(nm, length(threshs));
            metrics_lens      = zeros(nm, length(threshs));
            metrics_lens_knn  = zeros(nm, length(threshs));
            metrics_lens_knn2 = zeros(nm, length(threshs));
            for i = [1:length(threshs)]
                thresh = threshs(i);
                metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
            end

            %% plot f1
            ix = 11;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_rr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.f1'], ...
                'threshold', 'F1');

            %% plot prec
            ix = 9;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_rr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.prec'], ...
                'threshold', 'precision');

            %% plot recall
            ix = 10;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_rr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.recall'], ...
                'threshold', 'recall');

            %% plot jaccard
            ix = 12;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_rr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.jaccard'], ...
                'threshold', 'jaccard');
        end % end plot threshold 2 for row rand
        



        %% --------------------
        %% RowRandLoss
        %% --------------------
        %% RowRandLoss
        drop_ele_mode = 'col';
        drop_mode     = 'ind';
        elem_fracs    = [0.1 0.2 0.4 0.6 0.8];
        loss_rates    = [0.5];
        burst_size    = 1;

        if PLOT_COL_RAND1
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;

            for loss_rate = loss_rates
                thresh = 0.6;
                
                metrics_srmf      = zeros(nm, length(elem_fracs));
                metrics_srmf_knn  = zeros(nm, length(elem_fracs));
                metrics_lens      = zeros(nm, length(elem_fracs));
                metrics_lens_knn  = zeros(nm, length(elem_fracs));
                metrics_lens_knn2 = zeros(nm, length(elem_fracs));
                for i = [1:length(elem_fracs)]
                    elem_frac = elem_fracs(i);
                    metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                    metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                end

                %% plot mse
                ix = 1;
                plot_my(elem_fracs, ...
                    [metrics_srmf(ix, :); ...
                     metrics_srmf_knn(ix, :); ...
                     metrics_lens(ix, :); ...
                     metrics_lens_knn(ix, :); ...
                     metrics_lens_knn2(ix, :);], ...
                    {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                    [output_dir file '.ColRandLoss' int2str(loss_rate*100) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.mse'], ...
                    'loss rate', 'MSE');

                %% plot mae
                ix = 2;
                plot_my(elem_fracs, ...
                    [metrics_srmf(ix, :); ...
                     metrics_srmf_knn(ix, :); ...
                     metrics_lens(ix, :); ...
                     metrics_lens_knn(ix, :); ...
                     metrics_lens_knn2(ix, :);], ...
                    {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                    [output_dir file '.ColRandLoss' int2str(loss_rate*100) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.mae'], ...
                    'loss rate', 'MAE');

                %% plot cc
                ix = 3;
                plot_my(elem_fracs, ...
                    [metrics_srmf(ix, :); ...
                     metrics_srmf_knn(ix, :); ...
                     metrics_lens(ix, :); ...
                     metrics_lens_knn(ix, :); ...
                     metrics_lens_knn2(ix, :);], ...
                    {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                    [output_dir file '.ColRandLoss' int2str(loss_rate*100) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.cc'], ...
                    'loss rate', 'correlation coefficient');
            end
        end % end PLOT COL RAND

        if PLOT_CR_THRESH1
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;
            
            %% - elem_frac = 0.2
            loss_rate = 0.5;
            elem_frac = 0.2;

            metrics_srmf      = zeros(nm, length(threshs));
            metrics_srmf_knn  = zeros(nm, length(threshs));
            metrics_lens      = zeros(nm, length(threshs));
            metrics_lens_knn  = zeros(nm, length(threshs));
            metrics_lens_knn2 = zeros(nm, length(threshs));
            for i = [1:length(threshs)]
                thresh = threshs(i);
                metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
            end

            %% plot f1
            ix = 11;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_cr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.f1'], ...
                'threshold', 'F1');

            %% plot prec
            ix = 9;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_cr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.prec'], ...
                'threshold', 'precision');

            %% plot recall
            ix = 10;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_cr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.recall'], ...
                'threshold', 'recall');

            %% plot jaccard
            ix = 12;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_cr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.jaccard'], ...
                'threshold', 'jaccard');
        end % end plot threshold 1 for col rand

        if PLOT_CR_THRESH2
            %% 1. mag = 0.4, noise = 0.001
            sigma_mag   = 1;
            sigma_noise = 0.1;
            
            %% - elem_frac = 0.6
            loss_rate = 0.5;
            elem_frac = 0.6;

            metrics_srmf      = zeros(nm, length(threshs));
            metrics_srmf_knn  = zeros(nm, length(threshs));
            metrics_lens      = zeros(nm, length(threshs));
            metrics_lens_knn  = zeros(nm, length(threshs));
            metrics_lens_knn2 = zeros(nm, length(threshs));
            for i = [1:length(threshs)]
                thresh = threshs(i);
                metrics_srmf(:, i) = get_srmf(file, -1, 10, 'org', 'srmf', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_srmf_knn(:, i) = get_srmf(file, -1, 10, 'org', 'srmf_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens(:, i) = get_srmf(file, -1, 10, 'org', 'lens', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
                metrics_lens_knn2(:, i) = get_srmf(file, -1, 10, 'org', 'lens_knn2', '2d', drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh);
            end

            %% plot f1
            ix = 11;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_cr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.f1'], ...
                'threshold', 'F1');

            %% plot prec
            ix = 9;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_cr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.prec'], ...
                'threshold', 'precision');

            %% plot recall
            ix = 10;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_cr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.recall'], ...
                'threshold', 'recall');

            %% plot jaccard
            ix = 12;
            plot_my(threshs, ...
                [metrics_srmf(ix, :); ...
                 metrics_srmf_knn(ix, :); ...
                 metrics_lens(ix, :); ...
                 metrics_lens_knn(ix, :); ...
                 metrics_lens_knn2(ix, :);], ...
                {'SRMF', 'SRMF+KNN', 'LENS', 'LENS+KNN', 'LENS+KNN2'}, ...
                [output_dir file '.thresh_cr' num2str(loss_rate*100) '.loss' num2str(elem_frac) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.jaccard'], ...
                'threshold', 'jaccard');
        end % end plot threshold 2 for col rand

    end %% end files

end




%% get_totem: function description
function [ret] = get_srmf(file, group_size, r, opt_swap_mat, opt_type, opt_dim, drop_ele_mode, drop_mode, elem_frac, loss_rate, burst_size, sigma_mag, sigma_noise, thresh)

    srmf_dir = '../condor_data/subtask_compressive_sensing/condor/output/';
    scheme   = 'srmf_based_pred';
    seeds    = [1];

    if strcmpi(file, 'tm_3g_region_all.res0.002.bin60.sub.')
        num_frames = 24;
        width      = 120;
        height     = 100;

    elseif strcmpi(file, 'tm_3g_region_all.res0.004.bin60.sub.')
        num_frames = 24;
        width      = 60;
        height     = 60;

    elseif strcmpi(file, 'tm_download.sort_ips.ap.bgp.sub_CN.txt.3600.top400.')
        num_frames = 19;
        width      = 217;
        height     = 400;

    elseif strcmpi(file, 'tm_totem.')
        num_frames = 100;
        width      = 23;
        height     = 23;

    end


    if group_size == -1
        group_size = num_frames;
    end


    nm  = 12;
    ret = zeros(1, nm);
    cnt = zeros(1, nm);

    for seed = seeds
        filename = [scheme '.' file '.' int2str(num_frames) '.' int2str(width) '.' int2str(height) '.' int2str(group_size) '.r' int2str(r) '.' opt_swap_mat '.' opt_type '.' opt_dim '.' drop_ele_mode '.' drop_mode '.elem' num2str(elem_frac) '.loss' num2str(loss_rate) '.burst' int2str(burst_size) '.anom' num2str(sigma_mag) '.noise' num2str(sigma_noise) '.thresh' num2str(thresh) '.seed' int2str(seed) '.txt'];

        if ~(exist([srmf_dir filename]))
            fprintf('  %s%s\n', srmf_dir, filename);
            continue;
        end

        data = load([srmf_dir filename]);

        %% metrics: mse, mae, cc, ratio, tp, tn, fp, fn, ...
        for mi = [1:nm]
            if isnan(data(mi))
                continue;
            end
            ret(mi) = ret(mi) + data(mi);
            cnt(mi) = cnt(mi) + 1;
        end
    end

    ret(cnt>0) = ret(cnt>0) ./ cnt(cnt>0);

    fprintf('mse=%f, mae=%f, cc=%f, ratio=%f\n', ret(1), ret(2), ret(3), ret(4));
    fprintf('tp=%d, tn=%d, fp=%d, fn=%d\n', ret(5), ret(6), ret(7), ret(8));
    fprintf('prec=%f, recall=%f, f1=%f, jaccard=%f\n', ret(9), ret(10), ret(11), ret(12));
end


function plot_my(x, y, legends, file, x_label, y_label)

    markers = {'+','o','*','.','x','s','d','^','>','<','p','h'};
    lines   = {'-','--',':','-.'};
    font_size = 18;
    cnt = 1;

    clf;
    fh = figure;
    hold all;
    
    for yi = 1:size(y, 1)
        yy = y(yi, :);

        %% line
        lh = plot(x, yy);
        set(lh, 'LineStyle', char(lines(mod(cnt-1,length(lines))+1)));
        set(lh, 'LineWidth', 4);
        set(lh, 'marker', char(markers(mod(cnt-1,length(markers))+1)));
        set(lh, 'MarkerEdgeColor', 'auto');
        set(lh, 'MarkerFaceColor', 'auto');
        set(lh, 'MarkerSize', 12);

        cnt = cnt + 1;
    end


    set(gca, 'FontSize', font_size);
    set(fh, 'PaperUnits', 'points');
    set(fh, 'PaperPosition', [0 0 1024 768]);

    xlabel(x_label, 'FontSize', font_size);
    ylabel(y_label, 'FontSize', font_size);

    kh = legend(legends);
    set(kh, 'Box', 'off');
    set(kh, 'Location', 'BestOutside');
    % set(kh, 'Orientation', 'horizontal');
    % set(kh, 'Position', [.1,.2,.1,.2]);

    print(fh, '-dpng', [file '.png']);
end



function plot_my2(x, y, legends, file, x_label, y_label)

    markers = {'+','o','*','.','x','s','d','^','>','<','p','h'};
    lines   = {'-','--',':','-.'};
    font_size = 18;
    cnt = 1;

    clf;
    fh = figure;
    hold all;
    
    for i = 1:size(y, 1)
        xx = x(i, :);
        yy = y(i, :);

        %% line
        lh = plot(xx, yy);
        set(lh, 'LineStyle', char(lines(mod(cnt-1,length(lines))+1)));
        set(lh, 'LineWidth', 4);
        set(lh, 'marker', char(markers(mod(cnt-1,length(markers))+1)));
        set(lh, 'MarkerEdgeColor', 'auto');
        set(lh, 'MarkerFaceColor', 'auto');
        set(lh, 'MarkerSize', 12);

        cnt = cnt + 1;
    end


    set(gca, 'FontSize', font_size);
    set(fh, 'PaperUnits', 'points');
    set(fh, 'PaperPosition', [0 0 1024 768]);

    xlabel(x_label, 'FontSize', font_size);
    ylabel(y_label, 'FontSize', font_size);

    kh = legend(legends);
    set(kh, 'Box', 'off');
    set(kh, 'Location', 'BestOutside');
    % set(kh, 'Orientation', 'horizontal');
    % set(kh, 'Position', [.1,.2,.1,.2]);

    print(fh, '-dpng', [file '.png']);
end

